package com.lsk.admin.member;

import com.jfinal.core.Controller;
import com.lsk.util.PageUtil;
import com.lsk.util.ReturnData;

import java.util.Map;

public class MemberController extends Controller {

    MemberService memberService=new MemberService();

    public void memberList(){

        renderJsp("memberList.jsp");

    }

    /**
     * 按照搜索框查询
     */
    public void searchByName(){
        String key = getPara("key");
        setAttr("key",key);
        renderJsp("memberList.jsp");
    }
    public void memberListData(){

        String key=getPara("key");
        String pageStr=getPara("page");

        String limitStr=getPara("limit");
        String key1=key==null?"":key;
        int page=pageStr==null?0:Integer.parseInt(pageStr);

        int limit=limitStr==null?0:Integer.parseInt(limitStr);

        Map map=memberService.memberListDataService(page,limit,key1);

        renderJson(map);

    }

    /**
     * 下级会员
     */
    public void sonMember(){

        String id=getPara("id");
        setAttr("id",id);
        renderJsp("sonMember.jsp");

    }
    /**
     * 下级会员数据
     */
    public void sonMemberData(){


        String parentId=getPara("parentId");


        String pageStr=getPara("page");

        String limitStr=getPara("limit");

        int page=pageStr==null?0:Integer.parseInt(pageStr);

        int limit=limitStr==null?0:Integer.parseInt(limitStr);


        Map map=memberService.sonMemberDataService(page,limit,parentId);

        renderJson(map);
    }

    /**
     * 获利记录
     */
    public void memberRebateLog(){
        String memberId=getPara("memberId");
        setAttr("memberId",memberId);
        renderJsp("memberRebateLog.jsp");
    }

    /**
     * 返利记录数据
     */
    public void memberRebateLogData(){

        String memberId=getPara("memberId");


        String pageStr=getPara("page");

        String limitStr=getPara("limit");

        int page=pageStr==null?0:Integer.parseInt(pageStr);

        int limit=limitStr==null?0:Integer.parseInt(limitStr);


        Map map=memberService.memberRebateLogDataService(page,limit,memberId);

        renderJson(map);

    }
    /**
     * 账户详情
     */
    public void memberAccountLog(){


        String memberId=getPara("memberId");

        setAttr("memberId",memberId);

        renderJsp("memberAccountLog.jsp");

    }



    /**
     * 账户详情数据
     */
    public void memberAccountLogData(){
        String memberId=getPara("memberId");


        String pageStr=getPara("page");

        String limitStr=getPara("limit");

        int page=pageStr==null?0:Integer.parseInt(pageStr);

        int limit=limitStr==null?0:Integer.parseInt(limitStr);


        Map map=memberService.memberAccountLogDataService(page,limit,memberId);

        renderJson(map);

    }
    /**
     * 成为分销商
     */
    public void member(){

        String page=getPara("page");

        page=page==null||"".equals(page)?"1":page;

        String limit=getPara("limit");

        limit=limit==null||"".equals(limit)?"10":limit;

        String shopId=getSession().getAttribute("shopId").toString();

        PageUtil pageUtil=memberService.MemberService(page,limit,shopId);

        setAttr("pageUtil",pageUtil);

        renderJsp("member.jsp");

    }
    /**
     * 通过成为分销商
     */
    public void passMember(){

        String id=getPara("id");

        ReturnData returnData=memberService.passMemberServie(id);

        renderJson(returnData);

    }
    /**
     * 驳回成为分销商
     */
    public void turnMember(){

        String id=getPara("id");

        ReturnData returnData=memberService.turnMemberService(id);

        renderJson(returnData);

    }

}
